import request from '@/utils/request';
import moment from 'moment';
import { debug } from 'util';

const fakeDB = {
  eseProject: {
    "code": 1148784465300947000,
    "name": "XXX医院",
    "type": "能源站项目",
    "address": "XXXXXXXXX",
    "memo": "新密市妇幼保健院于2018年12月30日乔迁新址。老院建筑面积约为1.6万平方米，新院冷热集中供应面积约为5万平方米。其实质为迁扩建项目。",
    "src": null,
    "info": null,
    "buildingArea": 40000,
    "coolPower": 4000,
    "heatPower": 4000,
    "electricPower": 4000,
    "delete": 0,
    "current": 1,
    "version": 1
  },// 项目信息
  eseProject_scheme: {
    "project_name": "名称",
    "project_info": "信息",
    "project_refrigeration": "制冷量",
    "project_electric": "耗电功率",
    "project_heating": "供热负荷",
    "project_water": "耗水量",
    "project_buildingarea": "建筑面积",
    "project_thumbpic": "缩略图",
  },// 项目信息
  eseDevices: 
  [
    {
      "code": 1153208077172867000,
      "name": "新密能源站",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208076900237300,
      "modeCode": 1153208077101564000,
      "linkedCode": -1,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "能源站",
      "typeName": "能源站",
      "projectName": "XXX医院",
      "linkedDeviceName": null
    },
    {
      "code": 1153208092079423500,
      "name": "内燃机",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208091941011500,
      "modeCode": 1153208092012314600,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "内燃机",
      "typeName": "内燃机",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208092247195600,
      "name": "余热机",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208092138143700,
      "modeCode": 1153208092192669700,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "余热机",
      "typeName": "余热机",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208092406579200,
      "name": "250直燃机",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208092289138700,
      "modeCode": 1153208092326887400,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "直燃机",
      "typeName": "直燃机",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208092519825400,
      "name": "175直燃机",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208092289138700,
      "modeCode": 1153208092326887400,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "直燃机",
      "typeName": "直燃机",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208092641460200,
      "name": "1#空气源热泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208092557574100,
      "modeCode": 1153208092591128600,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "空气源热泵",
      "typeName": "空气源热泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208092775678000,
      "name": "2#空气源热泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208092557574100,
      "modeCode": 1153208092591128600,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "空气源热泵",
      "typeName": "空气源热泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208092909895700,
      "name": "1#冷却塔",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208092817621000,
      "modeCode": 1153208092855369700,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷却塔",
      "typeName": "冷却塔",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208092989587500,
      "name": "2#冷却塔",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208092817621000,
      "modeCode": 1153208092855369700,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷却塔",
      "typeName": "冷却塔",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093069279200,
      "name": "3#冷却塔",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208092817621000,
      "modeCode": 1153208092855369700,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷却塔",
      "typeName": "冷却塔",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093178331100,
      "name": "1#冷却泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208093102833700,
      "modeCode": 1153208093132193800,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷却泵",
      "typeName": "冷却泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093258023000,
      "name": "2#冷却泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208093102833700,
      "modeCode": 1153208093132193800,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷却泵",
      "typeName": "冷却泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093337714700,
      "name": "3#冷却泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208093102833700,
      "modeCode": 1153208093132193800,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷却泵",
      "typeName": "冷却泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093413212200,
      "name": "4#冷却泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208093102833700,
      "modeCode": 1153208093132193800,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷却泵",
      "typeName": "冷却泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093539041300,
      "name": "1#冷水泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208093450961000,
      "modeCode": 1153208093488709600,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷水泵",
      "typeName": "冷水泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093614538800,
      "name": "2#冷水泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208093450961000,
      "modeCode": 1153208093488709600,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷水泵",
      "typeName": "冷水泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093715202000,
      "name": "3#冷水泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208093450961000,
      "modeCode": 1153208093488709600,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷水泵",
      "typeName": "冷水泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    },
    {
      "code": 1153208093849419800,
      "name": "4#冷水泵",
      "projectCode": 1148784465300947000,
      "typeCode": 1153208093450961000,
      "modeCode": 1153208093488709600,
      "linkedCode": 1153208077172867000,
      "address": null,
      "memo": null,
      "delete": 0,
      "current": 1,
      "version": 1,
      "modeName": "冷水泵",
      "typeName": "冷水泵",
      "projectName": "XXX医院",
      "linkedDeviceName": "新密能源站"
    }
  ]
  
  ,// 设备信息
  eseDeviceModeInfos: [
    {
      "devicemode_code": 1,
      "device_type": "制冷系统",
      "device_mode": "制冷系统",
      "device_manufacturer": "XX工厂",
    },
    {
      "devicemode_code": 2,
      "device_type": "满液式全热回收式水冷冷水机组",
      "device_mode": "满液式全热回收式水冷冷水机组",
      "device_manufacturer": "XX工厂",
      "device_curves": [
        {
          "curve_name": "性能曲线",
          "x_name": "负荷",
          "x_prop": "负荷",
          "y_name": "性能",
          "y_prop": "性能",
          "x": [1, 2, 2, 3, 4, 5, 5, 6, 7, 78, 8, 9],
          "y": [1, 2, 2, 3, 4, 5, 5, 6, 7, 78, 8, 9]
        }
      ],
      "device_props": [
        {
          "prop_name": "制冷量",
          "prop_value": "1896",
          "prop_unit": "Kw"
        },
        {
          "prop_name": "制冷功率",
          "prop_value": "365.4",
          "prop_unit": "Kw"
        },
        {
          "prop_name": "COP",
          "prop_value": "5.18",
        }
      ],
    },
    {
      "devicemode_code": 3,
      "device_type": "螺杆式冷水机组",
      "device_mode": "螺杆式冷水机组",
      "device_manufacturer": "XX工厂",
      "device_curves": [
        {
          "curve_name": "性能曲线",
          "x_name": "负荷",
          "x_prop": "负荷",
          "y_name": "性能",
          "y_prop": "性能",
          "x": [1, 2, 2, 3, 4, 5, 5, 6, 7, 78, 8, 9],
          "y": [1, 2, 2, 3, 4, 5, 5, 6, 7, 78, 8, 9]
        }
      ],
      "device_props": [
        {
          "prop_name": "制冷量",
          "prop_value": "1920",
          "prop_unit": "Kw"
        },
        {
          "prop_name": "制冷功率",
          "prop_value": "296",
          "prop_unit": "Kw"
        },
        {
          "prop_name": "COP",
          "prop_value": "6.48",
        }
      ],
    },
    {
      "devicemode_code": 4,
      "device_type": "水却水泵",
      "device_mode": "水却水泵",
      "device_manufacturer": "XX工厂",
      "device_props": [
        {
          "prop_name": "流量",
          "prop_value": "423",
          "prop_unit": "m³/h"
        },
        {
          "prop_name": "扬程",
          "prop_value": "30",
          "prop_unit": "m"
        },
        {
          "prop_name": "功率",
          "prop_value": "55",
          "prop_unit": "Kw"
        }
      ],
    },
    {
      "devicemode_code": 5,
      "device_type": "水冻水泵",
      "device_mode": "水冻水泵",
      "device_manufacturer": "XX工厂",
      "device_props": [
        {
          "prop_name": "流量",
          "prop_value": "329",
          "prop_unit": "m³/h"
        },
        {
          "prop_name": "扬程",
          "prop_value": "41",
          "prop_unit": "m"
        },
        {
          "prop_name": "功率",
          "prop_value": "75",
          "prop_unit": "Kw"
        }
      ],
    },
    {
      "devicemode_code": 6,
      "device_type": "冷却塔",
      "device_mode": "冷却塔",
      "device_manufacturer": "XX工厂",
      "device_props": [
        {
          "prop_name": "流量",
          "prop_value": "500",
          "prop_unit": "m³/h"
        },
        {
          "prop_name": "功率",
          "prop_value": "2*5.5",
          "prop_unit": "Kw"
        }
      ],
    },
  ],
  eseDeviceModePoints: [
    {
      "devicemode_code": 1,
      "device_type": "制冷系统",
      "device_mode": "制冷系统",
      "device_manufacturer": "XX工厂",
      "device_points": [
        {
          "point_name": "开关",
          "point_type": "D",
        },
        {
          "point_name": "ERR",
          "point_h": 4.0,
          "point_l": 3.0,
          "point_type": "A",
        },
        {
          "point_name": "COP",
          "point_h": 6.0,
          "point_l": 5.0,
          "point_type": "A",
        },
        {
          "point_name": "制冷量",
          "point_unit": "Kw",
          "point_type": "A",
        },
        {
          "point_name": "功率",
          "point_unit": "Kw",
          "point_type": "A",
        },
        {
          "point_name": "冷却水进水温度",
          "point_h": 37.0,
          "point_l": 35.0,
          "point_type": "A",
          "point_unit": "°C",
        },
        {
          "point_name": "冷却水出水温度",
          "point_h": 37.0,
          "point_l": 35.0,
          "point_type": "A",
          "point_unit": "°C",
        },
        {
          "point_name": "冷冻水进水温度",
          "point_h": 13.0,
          "point_l": 11.0,
          "point_type": "A",
          "point_unit": "°C",
        },
        {
          "point_name": "冷冻水出水温度",
          "point_h": 8.0,
          "point_l": 6.0,
          "point_type": "A",
          "point_unit": "°C",
        },
        {
          "point_name": "冷却水耗水",
          "point_type": "A",
          "point_unit": "m³h/",
        },
        {
          "point_name": "冷冻水耗水",
          "point_type": "A",
          "point_unit": "m³h/",
        },
        {
          "point_name": "总耗水",
          "point_type": "A",
          "point_unit": "m³h/",
        },
      ]
    },
    {
      "devicemode_code": 2,
      "device_points": [
        {
          "point_name": "开关",
          "point_type": "D",
        },
        {
          "point_name": "功率",
          "point_unit": "Kw",
          "point_h": 365.4,
          "point_l": 5.5,
          "point_type": "A",
        },
        {
          "point_name": "制冷量",
          "point_unit": "Kw",
          "point_type": "A",
        },
        {
          "point_name": "COP",
          "point_type": "A",
        },
        {
          "point_name": "累计运行时间",
          "point_unit": "h",
          "point_type": "",
        }
      ]
    },
    {
      "devicemode_code": 3,
      "device_type": "水泵",
      "device_mode": "水泵",
      "device_manufacturer": "XX工厂",
      "device_points": [
        {
          "point_name": "开关",
          "point_type": "D",
        }
      ]
    },
    {
      "devicemode_code": 4,
      "device_type": "冷却塔",
      "device_mode": "冷却塔",
      "device_manufacturer": "XX工厂",
      "device_points": [
        {
          "point_name": "1#风扇开关",
          "point_type": "D",
        },
        {
          "point_name": "2#风扇开关",
          "point_type": "D",
        }
      ]
    },
  ],
  eseServices: [{
    "project_name": "XX医院",
    "service_code": "001_001_001_001",
    "service_name": "制冷系统采集服务",
    "service_IP": "192.10.0.1",
    "service_address": "1#制冷机房",
    "service_status": 1,
    "service_time": "1",
    "service_tags": ["采集", "制冷"]
  },
  {
    "project_name": "XX医院",
    "service_code": "001_001_001_002",
    "service_name": "供暖系统采集服务",
    "service_IP": "192.10.0.2",
    "service_address": "1#机房",
    "service_status": 1,
    "service_time": "1",
    "service_tags": ["采集", "供暖"]
  },
  {
    "project_name": "XX医院",
    "service_code": "001_001_001_003",
    "service_name": "供电系统采集服务",
    "service_IP": "192.10.0.3",
    "service_address": "配电房",
    "service_status": 1,
    "service_time": "1",
    "service_tags": ["采集", "配电"]
  }
  ]
  , eseOmLog: {
    "dailyLog_date": '2019-4-1',
    "dailyLog_groupName": '甲班',
    "dailyLog_dutyTime": '8:00~16:00',
    "dailyLog_manager": {
      "user_name": "李子明",
      "user_type": "操作工"
    },
    "dailyLog_user": [{
      "user_name": "张志维",
      "user_type": "电工"
    }, {
      "user_name": "相寿强",
      "user_type": "操作工"
    }],
    "dailyLog_content": [{
      "log_time": "8:00",
      "log_user": "相寿强",
      "log_content": "接班",
      "log_type": "交接班",

    }, {
      "log_time": "8:30",
      "log_user": "相寿强",
      "log_content": "调整冷冻水温度：8.5°C",
      "log_type": "操作",
    }
    ],
    "dailyLog_tags": [
      "设备无异常", "调温6次"
    ]
  },
  eseOMOrders: [{
    "order_no": "001_001_001_001_20190401_001",
    "project_name": "XX医院",
    "device_name": "散热水箱",
    "order_name": "定期巡检",
    "order_content": "查看设备运行情况",
    "order_opUser": "李子明",
    "order_checkUser": "张志维",
    "order_tags": ["巡检", "水箱", "楼顶"]
  },
  {
    "order_no": "001_001_001_001_20190401_001",
    "project_name": "XX医院",
    "device_name": "散热水箱",
    "order_name": "定期巡检",
    "order_content": "查看设备运行情况",
    "order_opUser": "李子明",
    "order_checkUser": "张志维",
    "order_tags": ["巡检", "水箱", "楼顶"]
  },
  {
    "order_no": "001_001_001_001_20190401_001",
    "project_name": "XX医院",
    "device_name": "散热水箱",
    "order_name": "定期巡检",
    "order_content": "查看设备运行情况",
    "order_opUser": "李子明",
    "order_checkUser": "张志维",
    "order_tags": ["巡检", "水箱", "楼顶"]
  },
  {
    "order_no": "001_001_001_001_20190401_001",
    "project_name": "XX医院",
    "device_name": "散热水箱",
    "order_name": "定期巡检",
    "order_content": "查看设备运行情况",
    "order_opUser": "李子明",
    "order_checkUser": "张志维",
    "order_tags": ["巡检", "水箱", "楼顶"]
  },
  {
    "order_no": "001_001_001_001_20190401_001",
    "project_name": "XX医院",
    "device_name": "散热水箱",
    "order_name": "定期巡检",
    "order_content": "查看设备运行情况",
    "order_opUser": "李子明",
    "order_checkUser": "张志维",
    "order_tags": ["巡检", "水箱", "楼顶"]
  },
  {
    "order_no": "001_001_001_001_20190401_001",
    "project_name": "XX医院",
    "device_name": "散热水箱",
    "order_name": "定期巡检",
    "order_content": "查看设备运行情况",
    "order_opUser": "李子明",
    "order_checkUser": "张志维",
    "order_tags": ["巡检", "水箱", "楼顶"]
  }
  ]
};

export async function queryEseProjects() {
  let objJsonStr = JSON.stringify(fakeDB.eseProject);
  let objs = [];
  for (let i = 0; i < 20; i++) {
    let newobj = JSON.parse(objJsonStr);
    newobj.key = i;
    objs.push(newobj);
  }
  return objs;
}


export async function queryEseProject() {
  return fakeDB.eseProject;
}

export async function queryEseDevices() {

  fakeDB.eseDevices.forEach((x, i) => {
    let deviceMode = fakeDB.eseDeviceModeInfos.find(f => f.devicemode_code === x.device_mode);
    if (deviceMode != undefined) {
      Object.keys(deviceMode).forEach((m, mi) => {
        x[m] = deviceMode[m];
      });
    }
    x["project_name"] = "XX医院";
  })
  return fakeDB.eseDevices;
}

export async function queryOmOrders() {
  return fakeDB.eseOMOrders;
}

function randData() {

  let arri = 0;
  let tmppd = [];
  const eer = Math.round((3 + Math.random()) * 10) / 10;

  const cop = Math.round((5 + Math.random()) * 10) / 10;
  const powerPercent = Math.round((Math.random()) * 10) / 10;
  const coolPower = Math.round((1896 + 1920) * powerPercent * 100) / 100;
  const power = Math.round((coolPower / cop) * 100) / 100;
  tmppd[arri] = 1;
  arri++;
  tmppd[arri] = eer; arri++;
  tmppd[arri] = cop; arri++;
  tmppd[arri] = coolPower; arri++;
  tmppd[arri] = power; arri++;

  const te1 = Math.round((11 + 2 * Math.random()) * 10) / 10;

  const te2 = Math.round((6 + 2 * Math.random()) * 10) / 10;
  tmppd[arri] = te1; arri++;
  tmppd[arri] = te2; arri++;

  const te4 = Math.round((30 + 2 * Math.random()) * 10) / 10;
  const te3 = Math.round((te4 + 4 + 2 * Math.random()) * 10) / 10;

  tmppd[arri] = te3; arri++;
  tmppd[arri] = te4; arri++;

  const flow1 = Math.round(power * 3.6 / 4.2 / (te1 - te2) * 100) / 100;
  const flow2 = Math.round(power * 3.6 / 4.2 / (te3 - te4) * 100) / 100;
  const rtflow = Math.round((flow1 * 0.005 + flow2 * 0.012) * 100) / 100;

  tmppd[arri] = flow1; arri++;
  tmppd[arri] = flow1; arri++;
  tmppd[arri] = rtflow; arri++;

  return tmppd;

}


export async function queryRtDatas() {
  let objs = [];
  let values = randData();

  let nowStr = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");

  let obj = fakeDB.eseDevices.find(f => f.device_mode === 1);
  let devicePoint = fakeDB.eseDeviceModePoints.find(f => f.devicemode_code === obj.device_point);
  let deviceMode = fakeDB.eseDeviceModeInfos.find(f => f.devicemode_code === obj.device_mode);
  devicePoint.device_points.forEach((p, pi) => {

    let pobj = p;
    Object.keys(obj).forEach((m, mi) => {
      pobj[m] = obj[m];
    });
    pobj["data_value"] = values[pi];
    pobj["data_time"] = nowStr;
    pobj["project_name"] = "XX医院";
    pobj["data_tags"] = [];
    pobj["point_code"] = pi;
    pobj["data_tags"] = ["正常"];
    objs.push(pobj);
  });
  return objs;
}


export async function queryRangRtDatas(payload) {
  let objs = [];
  for (let i = 0; i < 72; i++) {

    let values = randData();
    objs[i] = values[payload.point_code];
  }

  return objs;

}




export async function queryEseDcServices() {
  let nowStr = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
  fakeDB.eseServices.forEach((x, i) => {
    x["service_time"] = nowStr;
  })
  return fakeDB.eseServices;
}
export async function queryDailyLogs() {
 

  let objJsonStr = JSON.stringify(fakeDB.eseOmLog);
  let objs = [];
  for (let i = 0; i < 20; i++) {
    let newobj = JSON.parse(objJsonStr);
    newobj.key = i;
    objs.push(newobj);
  }
  
  return objs;


  
}




